import app


class RegLoginApi:

    def __init__(self, session):
        self.session = session
                                # 域名 + 路径
        self.img_verify_code_url = app.BASE_HOST + "/common/public/verifycode1/{}"
        self.phone_verify_code_url = app.BASE_HOST + "/member/public/sendSms"
        self.user_register_url = app.BASE_HOST + "/member/public/reg"
        self.user_login_url = app.BASE_HOST + "/member/public/login"


    # 获取图片验证码接口
    def get_img_verify_code(self, r):
        return self.session.get(url = self.img_verify_code_url.format(r))


    # 获取短信验证码接口
    def get_phone_verify_code(self, phone, imgVerifyCode, type="reg"):
        data_dict = {"phone":phone,"imgVerifyCode":imgVerifyCode,"type":type}
        return self.session.post(url=self.phone_verify_code_url,data=data_dict)


    # 注册接口
    def user_register(self, phone, password, verifycode, phone_code, dy_server, invite_phone=None):
        data_dict ={"phone":phone,"password":password,"verifycode":verifycode,"phone_code":phone_code,"dy_server":dy_server,"invite_phone":invite_phone}
        return self.session.post(url=self.user_register_url,data=data_dict)


    # 登录接口
    def user_login(self, keywords, password):
        data_dict = {"keywords":keywords,"password":password}
        return self.session.post(url=self.user_login_url,data=data_dict)

